#include "StdAfx.h"
#include "LookUp.h"

bool LookUp::_tablesPopulated = false;
	
uchar* LookUp::_nDiv10 = NULL;
uchar* LookUp::_nRem10 = NULL;
	
uchar* LookUp::_nRem100 = NULL;
uchar* LookUp::_nDiv100 = NULL;

void LookUp::Populate()
{
	if (_tablesPopulated) return;

	_nRem10 = (uchar *)malloc(100*sizeof(uchar));
	_nDiv10 = (uchar *)malloc(100*sizeof(uchar));

	if (_nRem10 == NULL || _nDiv10 == NULL)
	{
		//die
	}

	int nDiv = 0;
	int nRem = 0;

	for (int i = 0; i < 100; i++)
	{
		_nDiv10[i] = nDiv;
		_nRem10[i] = nRem;
		
		nRem++;

		if (nRem == 10)
		{
			nRem = 0;
			nDiv++;
		}
	}

	_nRem100 = (uchar *)malloc(10000*sizeof(uchar));
	_nDiv100 = (uchar *)malloc(10000*sizeof(uchar));

	if (_nRem100 == NULL || _nDiv100 == NULL)
	{
		//die
	}

	nDiv = 0;
	nRem = 0;

	for (int i = 0; i < 10000; i++)
	{
		_nDiv100[i] = nDiv;
		_nRem100[i] = nRem;
		
		nRem++;

		if (nRem == 100)
		{
			nRem = 0;
			nDiv++;
		}
	}
}

uchar LookUp::NDiv100(int i)
{
	if (!_tablesPopulated) Populate();

	return _nDiv100[i];
}

uchar LookUp::NRem100(int i)
{
	if (!_tablesPopulated) Populate();

	return _nRem100[i];
}

uchar LookUp::NDiv10(int i)
{
	if (!_tablesPopulated) Populate();

	return _nDiv10[i];
}

uchar LookUp::NRem10(int i)
{
	if (!_tablesPopulated) Populate();

	return _nRem10[i];
}